package com.fqgj.xjd.user.dao.impl;

import com.fqgj.common.base.AbstractBaseMapper;
import com.fqgj.xjd.user.dao.UserContactCarrierDao;
import com.fqgj.xjd.user.entity.UserContactCarrierEntity;
import com.fqgj.xjd.user.entity.business.UserCarrierStatisticsEntity;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.springframework.stereotype.Repository;

import java.util.*;

/**
 * User: zhangxingyun
 * Date: 2017-07-20
 * Time: 18:38:53.077
 */

@Repository
public class UserContactCarrierDaoImpl extends AbstractBaseMapper<UserContactCarrierEntity> implements UserContactCarrierDao {

    @Override
    public UserContactCarrierEntity selectByUserCode(String userCode) {
        return getSqlSession().selectOne(getStatement("selectByUserCode"), userCode);
    }

    @Override
    public int deleteByUserCode(String userCode) {
        return getSqlSession().update(getStatement("deleteByUserCode"), userCode);
    }

    @Override
    public List<UserContactCarrierEntity> selectUsersByUserCode(String userCode) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("userCode", userCode);
        params.put("deleted", 0);
        return super.selectByParams(params);
    }

    @Override
    public List<UserContactCarrierEntity> selectUsersByStatus(Integer status) {
        if (Objects.isNull(status)) {
            return Lists.newArrayList();
        }
        Map<String, Object> params = Maps.newHashMap();
        params.put("status", status);
        params.put("deleted", 0);
        return super.selectByParams(params);
    }

    @Override
    public List<UserContactCarrierEntity> selectUsersByUserCodeAndStatus(String userCode, Integer status) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("userCode", userCode);
        params.put("status", status);
        return super.selectByParams(params);
    }

    @Override
    public List<UserCarrierStatisticsEntity> selectUserCarrierStatistics(Date startDate, Date endDate) {
        Map<String, Object> params = new HashMap<>();
        params.put("startDate", startDate);
        params.put("endDate", endDate);
        return getSqlSession().selectList(getStatement("selectUserCarrierStatistics"), params);
    }
}